package JRadioButton;
import javax.swing.*;

public class MyFrame extends JFrame{
    public MyFrame()
    {
        this.setSize(350,200);
        this.setTitle("JRadioButton Demo.");
        this.setLayout(null); // 将JFrame的布局设置为空，通过坐标定位

        JLabel sex = new JLabel("性别:");
        JRadioButton r1 = new JRadioButton("男",true);
        JRadioButton r2 = new JRadioButton("女");
        ButtonGroup bg = new ButtonGroup();
        bg.add(r1);
        bg.add(r2);
        sex.setBounds(10,20,50,30);
        r1.setBounds(60,20,60,30);
        r2.setBounds(130,20,60,30);
        this.add(sex);
        this.add(r1);
        this.add(r2);

        this.setLocationRelativeTo(null); // 使窗口居中
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 响应窗口关闭按钮
        this.setVisible(true); // 将窗口显示出来
    }
    public static void main(String[] args)
    {
        new MyFrame();
    }
}